//Copyright 2010 Balazs Keri, Imre Keri
//
//This file is part of FireworksCreator.
//
//FireworksCreator is free software: you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation, either version 3 of the License, or
//(at your option) any later version.
//
//FireworksCreator is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//GNU General Public License for more details.
//
//You should have received a copy of the GNU General Public License
//along with FireworksCreator.  If not, see <http://www.gnu.org/licenses/>.
//
#ifndef _OBJTREEVIEW_H
#define _OBJTREEVIEW_H
//
#include <QTreeWidget>
#include "objectview.h"
//
class MainView;
class ActionState;
class ObjTreeView:public QTreeWidget,public DataObjectView
{
   Q_OBJECT
   Q_DISABLE_COPY(ObjTreeView)
//construction
public:
   ObjTreeView(MainView *main_view,const QMetaObject *filter_type,bool groups,bool recursive);
   ~ObjTreeView();
//slots
public slots:
   void activate_actions();
   void deactivate_actions();
   void set_current(Identified *current);
protected slots:
   void on_currentItemChanged(QTreeWidgetItem *current,QTreeWidgetItem *previous);
   void on_itemDoubleClicked(QTreeWidgetItem *item,int column);
private slots:
   void on_new_pt();
   void on_new_et();
   void on_new_g();
   void on_delete();
//signals
signals:
   void current_changed(Identified*);
   void double_clicked(Identified*);
//DataObjectView
protected:
   void handle_object_changed(Identified *old_object);
   //void handle_pre_primitive(const Primitive &prim);
   void handle_post_primitive(const Primitive &prim);
   //void handle_fail_primitive(const Primitive &prim);
//QWidget
protected:
   void focusInEvent(QFocusEvent *event);
//implementation
private:
   class Item;
   typedef QMultiHash<Id,Item*> ItemHash;
   const QMetaObject *const filter_type;
   bool const groups;
   bool const recursive;
   ItemHash item;
   void handle_insert_containment(Id parent_id,Id child_id);
   void handle_remove_containment(Id parent_id,Id child_id);
   void handle_move_child(Id parent_id,int from,int to);
   void populate_item_data(QTreeWidgetItem *parent);
   void depopulate_item_data(QTreeWidgetItem *parent);
   bool test_filter(const Identified *object) const;
   int get_child_index(const Identified *parent,const Identified *child) const;
   void create_object(const QMetaObject *type);
   void delete_object(Identified *object);
//action handling
private:
   ActionState *new_pt_state;
   ActionState *new_et_state;
   ActionState *new_g_state;
   ActionState *delete_state;
};
//
#endif